package mk.game.key
{
	import Lii.FTG.Key.AtkKey;
	import Lii.FTG.Key.CrossKey;
	import Lii.FTG.Key.KeyCatch;
	import Lii.FTG.Key.KeyboardKey;
	import Lii.events.FTGKeyEvent;
	
	import game.tileMap.view.PartySet;
	
	import mk.gamemap.view.sprite.CharView;
	
	public class KeyController
	{
		public var myKeyCatch:KeyCatch
		private var crossKey:CrossKey;
		private var atkKey:AtkKey;
		public var actor:PartySet
		
		public var isCtrl:Boolean;
		public function KeyController(keyCatch:KeyCatch)
		{
			
			myKeyCatch=keyCatch;
			init();
			
		}
		
		private function init():void{
			
			isCtrl=true;
			
			

		}
		
		
		
		public function setCrossKeys(upKey:uint,downKey:uint,leftKey:uint,rightKey:uint):void{
			var up:KeyboardKey=new KeyboardKey(upKey);
			var down:KeyboardKey=new KeyboardKey(downKey);
			var left:KeyboardKey=new KeyboardKey(leftKey);
			var right:KeyboardKey=new KeyboardKey(rightKey);
			crossKey=new CrossKey(myKeyCatch,up,down,left,right);
			
			crossKey.upBinding(upUp,downUp,leftUp,rightUp)
			crossKey.downBinding(upF,downF,leftF,rightF,null,null,null,null)
			//crossKey.addEventListener(FTGKeyEvent.onCrossDown_LEFTRIGHT,left_rightF);
			//crossKey.addEventListener(FTGKeyEvent.onCrossUp_LEFTRIGHT,left_rightUp);
			crossKey.holdBinding(upF,downF,leftF,rightF);
			crossKey.start();
		}
		
		public function setAtkKeys(A:uint,B:uint,C:uint,D:uint):void{
			var atk1:KeyboardKey=new KeyboardKey(A,"A");
			var atk2:KeyboardKey=new KeyboardKey(B,"B");
			var atk3:KeyboardKey=new KeyboardKey(C,"C");
			var atk4:KeyboardKey=new KeyboardKey(D,"D");
			atkKey=new AtkKey(myKeyCatch,atk1,atk2,atk3,atk4);
			atkKey.addEventListener(FTGKeyEvent.KEY_DOWN,atkDown)
			//atkKey.addEventListener(FTGKeyEvent.KEY_UP,atkUp)
			//atkKey.addEventListener(FTGKeyEvent.KEY_HOLD,atkHold)
			atkKey.start();
		}
		
		public function setActor(actor:PartySet):void{
			this.actor=actor
			
		}
		
		private function upF(e:FTGKeyEvent):void {
			if(actor.ctrl){
				actor.moveUp();
			}
			
		}
		
		private function downF(e:FTGKeyEvent):void {
			if(actor.ctrl){
				actor.moveDown();
			}
				
		}
		
		private function leftF(e:FTGKeyEvent):void {
			if(actor.ctrl){
				actor.moveLeft();
			}
			
		}
		
		private function rightF(e:FTGKeyEvent):void {
			if(actor.ctrl){
				actor.moveRight();
			}
			
			
			
		}
		
		private function rightD(e:FTGKeyEvent):void {
			
			
			
		}
		
		private function left_rightF(e:FTGKeyEvent):void {
			
		}
		
	//--------------------------------------------------------------------------------------------------	
		private function upUp(e:FTGKeyEvent):void {
			
			
			
			
		}
		
		private function downUp(e:FTGKeyEvent):void {
			
		}
		
		private function leftUp(e:FTGKeyEvent):void {
			
		}
		
		private function rightUp(e:FTGKeyEvent):void {
			
			
		}
		
		private function left_rightUp(e:FTGKeyEvent):void {
			
		}
	//----------------------------------------------------------------------------------------------	
		private function atkDown(e:FTGKeyEvent):void {
			
			
			if (e.keyName=="A"){
					//actor.attack();
				if (crossKey._key_down.isDown()){
				//	soldier.rush_Attack();
				}else{
				//	actor.attack();
				}
			}
			if (e.keyName=="B"){
			
			}
			if (e.keyName=="C"){
				
			}
		}
	}
}